<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>规则集信息修改</title>
<link href="../../static/plugin/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/plugin/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-edit.css" rel="stylesheet" type="text/css"/>
<script src="../../static/plugin/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/plugin/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/plugin/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<script src="../../ffres/dict/city.js" type="text/javascript"></script>
<script src="../../ffres/dict/org.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout" scroll="no" style="overflow: auto;">
	<form id="ff" method="post">
		<div class="esaas-info-title">规则集信息</div>
		<table class="esaas-info-edit-table">
			<tr>
				<td width="15%" align="right">规则集编号：</td>
				<td width="35%"><input class="easyui-textbox" type="text" readOnly
					name="ruleCollId" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">规则集名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text" 
					name="ruleCollDesc" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">规则集类型：</td>
				<td width="35%"><select class="easyui-combobox"
					id="ruleCollType" name="ruleCollType"
					style="width: 100%; height: 25px;"
					data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:RULE_COLL_TYPE">
				</select></td>
				<td width="15%" align="right">规则集版本：</td>
				<td width="35%"><input class="easyui-textbox" type="text" 
					name="ruleCollVersion" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr class="specialApproval">
				<td width="15%" align="right">适用抵押物选择：</td>
				<td width="35%"><select class="easyui-combobox"
										id="adapterCustomDim1Select" name="adapterCustomDim1Select"
										style="width: 100%; height: 25px;"
										valueField="enname" textField="cnname"
										data-options="required:true,editable:false,data:RULE_MORT_SELECT,onChange:mortSelectOnChange">
				</select></td>
				<td width="15%" align="right">适用机构选择：</td>
				<td width="35%"><select class="easyui-combobox"
										id="adapterOrgNoSelect" name="adapterOrgNoSelect"
										style="width: 100%; height: 25px;"
										valueField="enname" textField="cnname"
										data-options="required:true,editable:false,data:RULE_ORG_SELECT,onChange:orgSelectOnChange">
				</select></td>
			</tr>
			<tr class="specialApproval">
				<td class="adapterCustomDim1Cls" width="15%" align="right">适用抵押物地址：</td>
				<td class="adapterCustomDim1Cls" width="35%"><select class="easyui-combobox"
									 id="adapterCustomDim1" name="adapterCustomDim1"
									 style="width: 100%; height: 50px;"
									 valueField="enname" textField="cnname" groupField="parent"
									 multiple="true" multiline="true"
									 data-options="required:false,editable:false,data:CUSTOM_CITY">
				</select></td>
				<td class="adapterBlank" width="15%"></td>
				<td class="adapterBlank" width="35%"></td>
				<td class="adapterOrgNoCls" width="15%" align="right">适用机构：</td>
				<td class="adapterOrgNoCls" width="35%"><select class="easyui-combobox"
									id="adapterOrgNo" name="adapterOrgNo"
									style="width: 100%; height: 50px;"
									multiple="true" multiline="true"
									data-options="required:false,editable:false,valueField:'enname',textField:'cnname',data:CUSTOM_ORG">
				</select></td>
			</tr>
			<tr>
				<td width="15%" align="right">规则集状态：</td>
				<td width="35%"><select class="easyui-combobox"
					id="ruleCollState" name="ruleCollState"
					style="width: 100%; height: 25px;" 
					data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:RULE_COLL_STATE">
				</select></td>
				<td width="15%" align="right">创建用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="createUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">创建日期：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="createTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">最后修改时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="updateTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">最新变更用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="updateUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>

	<table id="detailDg" class="easyui-datagrid" style="width:95%;height:55%"
		   data-options="checkbox:true,selectOnCheck:true,collapsible:true,method:'post'"
		   toolbar="#detailTb"
		   title="规则明细"
		   rownumbers="true" pagination="true" pageSize="5" pagePosition="top" pageList="[5,10,20]">
		<thead>
		<tr>
			<th data-options="field:'checked',checkbox:true,resizable:true" >选择</th>
			<!--<th data-options="field:'dtlId',resizable:true" >规则配置明细ID</th>-->
			<th data-options="field:'ruleCollId',resizable:true" >规则集ID</th>
			<th data-options="field:'ruleId',resizable:true" sortable="true">规则ID</th>
			<th data-options="field:'ruleName',resizable:true" >规则名称</th>
			<th data-options="field:'ruleCfgDesc',resizable:true" >规则描述配置</th>
			<th data-options="field:'ruleTyp',resizable:true" formatter="formatter_RULE_TYPE">规则类型</th>
			<th data-options="field:'createUser',resizable:true" >创建用户</th>
			<th data-options="field:'createTime',resizable:true" >创建日期</th>
			<th data-options="field:'updateTime',resizable:true" >最后修改时间</th>
			<th data-options="field:'updateUser',resizable:true" >最新变更用户</th>
		</tr>
		</thead>
	</table>
	<div id="detailTb" style="padding:1px">
		<div style="margin-bottom:2px;text-align: left;">
			<a href="javascript:doRuleAdd()" class="easyui-linkbutton" iconCls="icon-add" plain="true">新增规则</a>
			<a href="javascript:doRuleParamUpdate(false)" class="easyui-linkbutton" iconCls="icon-edit" plain="true">参数配置修改</a>
			<a href="javascript:doRuleDelete()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除规则</a>
			<a href="javascript:doRuleParamView()" class="easyui-linkbutton" iconCls="icon-ok" plain="true">查看参数配置</a>
		</div>
	</div>
	<script>
		var ruleCollId ;
		var skipChangeEvent = false;
		$(function() {
			ruleCollId = $.getUrlParam('ruleCollId');
			$.restfulGet('../../api/s/rule/coll/info/' + ruleCollId,null,function(data){
					$('#ff').form('load', {
						ruleCollId : data.rows.ruleCollId,
						ruleCollDesc : data.rows.ruleCollDesc,
						ruleCollType : data.rows.ruleCollType,
						ruleCollVersion : data.rows.ruleCollVersion,
						ruleCollState : data.rows.ruleCollState,
                        adapterCustomDim1Select : data.rows.adapterCustomDim1Select,
                        adapterOrgNoSelect : data.rows.adapterOrgNoSelect,
						createUser : data.rows.createUser,
						createTime : data.rows.createTime,
						updateTime : data.rows.updateTime,
						updateUser : data.rows.updateUser
					});
                	$('#detailDg').datagrid({url:'../../api/s/rule/coll/details', queryParams:{ruleCollId: ruleCollId} });
					ruleTypeOnChange(data.rows.ruleCollType);
					mortSelectOnChange(data.rows.adapterCustomDim1Select);
					orgSelectOnChange(data.rows.adapterOrgNoSelect);
					if (data.rows.adapterCustomDim1)
						$('#adapterCustomDim1').combobox('setValues', data.rows.adapterCustomDim1);
					if (data.rows.adapterOrgNo)
						$('#adapterOrgNo').combobox('setValues', data.rows.adapterOrgNo);
			});
			$('#detailDg').on("SRuleInfoListChooseEvent", function(event, data) {
			    if (data.success) {
                    reloadDetailList();
				} else {
                    $.messager.alert('提示',data.message,'error');
				}
			});
		});


        function reloadDetailList(){
            $('#detailDg').datagrid('reload');
        };
	
		function submitForm() {
            var jsonData = $("#ff").serializeJson();
            if (jsonData.adapterOrgNo && !Array.isArray(jsonData.adapterOrgNo)) {
                jsonData.adapterOrgNo = [jsonData.adapterOrgNo];
            }
            if (jsonData.adapterCustomDim1 && !Array.isArray(jsonData.adapterCustomDim1)) {
                jsonData.adapterCustomDim1 = [jsonData.adapterCustomDim1];
            }
            if (jsonData.ruleCollType === '02') {
                // 等于特批
                $('#adapterCustomDim1Select').combobox({required:true});
                $('#adapterOrgNoSelect').combobox({required:true});
                skipChangeEvent = true;
                $('#adapterCustomDim1Select').combobox("setValue", jsonData.adapterCustomDim1Select);
                $('#adapterOrgNoSelect').combobox("setValue", jsonData.adapterOrgNoSelect);
                skipChangeEvent = false;
            } else {
                $('#adapterCustomDim1Select').combobox({required:false});
                $('#adapterOrgNoSelect').combobox({required:false});
                skipChangeEvent = true;
                $('#adapterCustomDim1Select').combobox("setValue", jsonData.adapterCustomDim1Select);
                $('#adapterOrgNoSelect').combobox("setValue", jsonData.adapterOrgNoSelect);
                skipChangeEvent = false;
            }
			if (!$('#ff').form('validate'))
				return;
			$.restfulPut('../../api/s/rule/coll/info', jsonData, function(data) {
				window.parent.reloadList();
			});
		};
		
		function closeForm(){
			window.parent.JLEUtil.closewin();
		}

		// 规则库操作
		function doRuleAdd() {
            JLEUtil.createModalWin('规则集新增规则', 'SRuleInfoListChoose.html?' + 'ruleCollId=' + ruleCollId);
		}

		function doRuleDelete() {
            var rows = $('#detailDg').datagrid('getSelections');
            if (rows && rows.length > 0) {
                var param = [];
                for (var i =0; i < rows.length; i++) {
                    var obj = {dtlId : rows[i].dtlId}
                    param.push(obj);
                }
                $.messager.confirm('删除提示', '你确定要删除选中的记录?', function(r){
                    if (r){
                        $.restfulDelete('../../api/s/rule/coll/detail/list', param, function(data) {
                            $.messager.alert('提示','记录删除成功!','info');
                            $('#detailDg').datagrid('reload');
                        });
                    }
                });
            } else {
                $.messager.alert('提示','请选择一条记录！','info');
            }
		}
		// 修改规则参数配置
		function doRuleParamUpdate(readonly) {
            var rows = $('#detailDg').datagrid('getSelections');
            if (rows && rows.length > 1) {
                $.messager.alert('提示', '请只选择一条记录进行操作！', 'info');
                return ;
            }
		    var row = $('#detailDg').datagrid('getSelected');
		    if (row) {
                window.parent.JLEUtil.createModalWin('规则集参数信息配置', 'SRuleCollParamCfg.html?' + 'ruleId=' + row.ruleId + '&dtlId='+row.dtlId + '&readonly=' + readonly);
			} else {
		        $.messager.alert('提示', '请选择一条记录！', 'info');
			}
		}
		// 查看规则参数配置
		function doRuleParamView() {
            doRuleParamUpdate(true);
		}


        function ruleTypeOnChange(val, old) {
            if (val === '02') {
                // 特批审批大纲 显示 specialApproval
                $('.specialApproval').show();
            } else {
                $('.specialApproval').hide();
            }
        }

        function mortSelectOnChange(newValue, oldValue) {
		    if (skipChangeEvent) {
		        return;
			}
            if (newValue === '1') {
                //  指定城市
                $('.adapterCustomDim1Cls').show();
                $('.adapterBlank').hide();
                $('#adapterCustomDim1').combobox({required:true})
            } else {
                $('.adapterCustomDim1Cls').hide();
                $('.adapterBlank').show();
                $('#adapterCustomDim1').combobox({required:false})
            }
        }

        function orgSelectOnChange(newValue, oldValue) {
            if (skipChangeEvent) {
                return;
            }
            if (newValue === '1') {
                if($('#adapterCustomDim1Select').combobox('getValue') !== "1") {
                    $('.adapterBlank').show();
                }
                //  指定机构
                $('.adapterOrgNoCls').show();
                $('#adapterOrgNo').combobox({required:true})
            } else {
                if($('#adapterCustomDim1Select').combobox('getValue') !== "1") {
                    $('.adapterBlank').hide();
                }
                $('.adapterOrgNoCls').hide();
                $('#adapterOrgNo').combobox({required:false})
            }
        }
	</script>
</body>
</html>
